// @import
import HeroCtrl, { g_oHeroCtrlMap } from "../../ctrl/HeroCtrl";
import UserData from "../../data/UserData";
import { g_oCmdHandlerMap } from "../ICmdHandler";

// @import
import mod_gameMsgProtocol = require("../../msg/mod_gameMsgProtocol");

/**
 * 用户移动结果处理器
 */
export default class UserMoveToResultHandler {
    /**
     * 处理结果
     * 
     * @param oResult 结果
     * @returns
     */
    handle(oResult: mod_gameMsgProtocol.msg.UserMoveToResult): void {
        if (null == oResult) {
            return;
        }

        if (oResult.moveUserId == UserData.getMyData()._nUserId) {
            // 如果是自己就不要移动了,
            return;
        }

        let oHeroCtrl: HeroCtrl = g_oHeroCtrlMap.get(oResult.moveUserId);

        oHeroCtrl.moveTo(cc.v2(
            oResult.moveToPosX, oResult.moveToPosY,
        ));
    }
}

// @autoExec
(function() {
    console.log("注册 -- UserMoveToResultHandler");
    g_oCmdHandlerMap.set(
        mod_gameMsgProtocol.msg.MsgCode.USER_MOVE_TO_RESULT, 
        new UserMoveToResultHandler()
    );
})();
